define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'car/task/index',
                    add_url: 'car/task/add',
                    edit_url: 'car/task/edit',
                    del_url: 'car/task/del',
                    multi_url: 'car/task/multi',
                    table: 'car_task',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        // {field: 'task_status', title: __('Status'), formatter:Table.api.formatter.toggle},
                        // {field: 'line_id', title: __('Line_id')},
                        {field: 'line.start_station', title: __('Line.start_station')},
                        {field: 'line.end_station', title: __('Line.end_station')},
                        {field: 'user.username', title: __('User.username')},
                        {field: 'carinfo.car_number', title: __('Carinfo.car_number'),operate: false},

                        {field: 'carinfo.car_name', title: __('Carinfo.car_name')},
                        {field: 'carinfo.passenger_num', title: __('Carinfo.passenger_num'),operate: false},
                        {field: 'passenger_true', title: __('Passenger_true'),operate: false},

                        // {field: 'carinfo_id', title: __('Carinfo_id')},
                        // {field: 'dri_id', title: __('Dri_id')},

                        {field: 'remarks', title: __('Remarks'),operate: false},


                        {field: 'user.mobile', title: __('User.mobile')},
                        {field: 'status', title: __('Status'),searchList: {"0":__('Normal'),"1":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'line.list', title: __('Line.list'),operate: false},
                        {field: 'line.mileage', title: __('Line.mileage')},
                        {field: 'line.duration', title: __('Line.duration'),operate: false},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'end_time', title: __('End_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'stop_time', title: __('Stop_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'seat_info', title: __('Seat_info'),operate: false},
                        // {field: 'line.run_time', title: __('Line.run_time'),operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});